package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"group-card/model/entity"
	"group-card/rpc/card/cardclient"
	"group-card/rpc/card/internal/svc"
)

type PublishCreateCardNumberLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPublishCreateCardNumberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishCreateCardNumberLogic {
	return &PublishCreateCardNumberLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

//region TODO: 自动生成卡号 Author:LiuYanLin Date:2023/04/04 周二 11:03

func (l *PublishCreateCardNumberLogic) PublishCreateCardNumber(in *cardclient.PublishCreateCardNumberRequest) (*cardclient.PublishCreateCardNumberResponse, error) {
	var ctx context.Context

	data, err := l.svcCtx.PublishModel.CreateCardNumber(ctx, &entity.CardPublishReq{
		Count: in.Count,
	})
	if err != nil {
		return nil, err
	}

	publish := &cardclient.PublishCreateCardNumberResponse{
		BeginNumber: data.BeginNumber,
		EndNumber:   data.EndNumber,
	}

	return publish, nil
}

//endregion
